﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SY.BasicData.Api.Read.Applications.Basic.Command;
using SY.BasicData.Api.Read.Applications.Cultivation.Command;
using SY.BasicData.Api.Read.Dto;
using SY.BasicData.Domain.Basic;
using SY.BasicData.Domain.Cultivation;
using SY.BasicData.ErrorCode;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;


namespace SY.BasicData.Api.Read.Controllers.Basic
{
    /// <summary>
    /// 控制器--读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BasicController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<BasicController> logger;

        public BasicController(IMediator mediator, ILogger<BasicController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 商品基础信息表
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回结果</returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<ApiPaging<BasicDto>>> GetBasicManagement([FromQuery] GetManagementCommand command)
        {
            try
            {
                logger.LogInformation("商品基础信息表展示成功");
                return await mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("商品基础信息表展示失败" + ex.Message);
                return await mediator.Send(command);
            }

        }
        /// <summary>
        /// 商品信息表
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回结果</returns>
        /// 
        [HttpGet]
        public Task<ApiResult<List<StoreModel>>> StoreList()
        {
            try
            {
                logger.LogInformation("商品表展示成功");
                GetStoreCommand command = new GetStoreCommand();
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("商品表展示失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 商品明细表
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回结果</returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<BasicDto>> GetBasicDetail([FromQuery] GetBasicDetailCommand command)
        {
            try
            {
                logger.LogInformation("商品明细表展示成功");

                return await mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("商品明细表展示失败" + ex.Message);
                throw;
            }




        }
      
    }
}
